package com.dhcc.core.api.shiro;

import com.dhcc.core.framework.util.ArrayUtil;
import com.dhcc.core.modules.system.entity.User;

/**
 * 权限检查
 * 
 * @ClassName: ApiPermissionCheckManager
 * @Description: TODO
 * @author: cyf
 * @date: 2018年1月3日 上午9:05:23
 */
public class ApiPermissionCheckManager {
    private final static ApiPermissionCheckManager me = new ApiPermissionCheckManager();

    public static ApiPermissionCheckManager me() {
        return me;
    }

    public boolean check(Object[] roles) {
        User user = ApiShiroKit.getUser();
        if (null == user) {
            return false;
        }
        String join = ArrayUtil.arrayToString(roles, ",");
        if (ApiShiroKit.hasAnyRoles(join)) {
            return true;
        }
        return false;
    }

    public boolean checkAll(Object[] permissions) {
        User user = ApiShiroKit.getUser();
        if (null == user) {
            return false;
        }
        String join = ArrayUtil.arrayToString(permissions, ",");
        if (ApiShiroKit.hasAnyPermission(join)) {
            return true;
        }
        return false;
    }

}
